/**
 * 创建实例，可以多个，当你需要请求多个不同域名的接口时
 */
import Request from './request';
import { getToken } from '@/utils/auth';

// 默认请求实例
const baseRequest = new Request({
  // 这里用 Easy Mock 模拟了真实接口
  baseURL: import.meta.env.VITE_BASE_URL,
  timeout: 5000,
  showLoading: false,
  interceptorHooks: {
    requestInterceptor: (config) => {
      const token = getToken();
      if (token) {
        config.headers.Authorization = token;
      }
      return config;
    },
    requestInterceptorCatch: (err) => {
      return err;
    },
    responseInterceptor: (res) => {
      return res.data;
    },
    responseInterceptorCatch: (err) => {
      return Promise.reject(err);
    },
  },
});

const mockRequest = new Request({
  baseURL: '/mock',
  timeout: 3000,
  showLoading: false,
});

// 创建其他示例，然后导出
// const otherRequest = new Request({...})

export { baseRequest, mockRequest };
